package com.broada.apm.service;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.broada.apm.ajax.PerformanceResult;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

@Path("apm/performances")
@Api(value="apm/performances" , description = "性能数据相关的APIs")
@Produces(MediaType.APPLICATION_JSON)
public interface PerformanceService {

	/**
	 * 查询时间段内性能信息
	 * @param appIds
	 * @param appId
	 * @param appName
	 * @param ip    节点IP
	 * @param port   节点端口
	 * @param txId  关键交易id
	 * @param txName  关键交易名称
	 * @param nodeIds
	 * @param startDate
	 * @param endDate
	 * @param size
	 * @return
	 */
	@GET
	@ApiOperation(value = "查询时间段内性能信息")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryPerformanceByDate(
			@ApiParam(value = "多个应用系统id", required = false) @QueryParam("appIds") String appIds, 
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId,
			@ApiParam(value = "应用系统名称", required = false) @QueryParam("appName") String appName, 
			@ApiParam(value = "拓扑节点id", required = false) @QueryParam("agentIds") String agentIds, 
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate,
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate, 
			@ApiParam(value = "粒度", required = false) @QueryParam("size") String size);


	/**
	 * 根据维度类型查询应用系能性能
	 * 
	 * @param appId
	 *          系统id
	 * @param dimensionType
	 *          维度类型
	 * @param perfTypes
	 *          性能指标类型数组
	 * @param startDate
	 *          开始时间
	 * @param endDate
	 *          结束时间
	 * @return
	 */
	@GET
	@Path("/dimensionType")
	@ApiOperation(value = "根据维度类型查询应用系能性能")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryPerformanceByDimensionType(
			@ApiParam(value = "applicationId", required = true) @QueryParam("applicationId") String applicationId,
			@ApiParam(value = "维度类型", required = true) @QueryParam("dimensionType") String dimensionType, 
			@ApiParam(value = "返回数据数量", required = true) @QueryParam("top") int top,
			@ApiParam(value = "排序字段", required = false) @QueryParam("orderBy") String orderBy, 
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate,
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate, 
			@ApiParam(value = "用以区分交易模式和非交易模式，其值可为system或business", required = true) @QueryParam("panelId") String panelId);

	@GET
	@Path("/area")
	@ApiOperation(value = "根据地理位置查询性能")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryPerformanceByArea(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@ApiParam(value = "排序字段", required = true) @QueryParam("sortField") String sortField,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate);
	/**
	 * 查询交易详细信息
	 * 
	 * @param appId
	 * @param resId
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@GET
	@Path("/trade/{resId}")
	@ApiOperation(value = "查询交易详细信息")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryDetailsPerformanceByKeyTrade(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@ApiParam(value = "交易类型id", required = true) @PathParam("resId") String resId,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate);

	/**
	 * 实时查询关键交易性能详情
	 * 
	 * @param appId
	 * @param resId
	 * @param lastDate
	 * @return
	 */
	@GET
	@Path("/trade/after/{resId}")
	@ApiOperation(value = "实时查询关键交易性能详情")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryDetailsPerformanceByLastDate(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@ApiParam(value = "交易类型id", required = true) @PathParam("resId") String resId,
			@ApiParam(value = "查询时间", required = true) @QueryParam("lastDate") long lastDate);

	@GET
	@Path("/page")
	@ApiOperation(value = "分页查询性能")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryPerformanceByPage(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@ApiParam(value = "返回数据量", required = true) @QueryParam("top") int top,
			@ApiParam(value = "排序字段", required = false) @QueryParam("sortField") String sortField, 
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate);

	@GET
	@Path("/page/{resId}")
	@ApiOperation(value = "根据粒度查询交易类型性能")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryPerformanceByPageId(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@ApiParam(value = "交易类型id", required = true) @PathParam("resId") String resourceId,
			@ApiParam(value = "查询字段", required = false) @QueryParam("field") String field, 
			@ApiParam(value = "粒度，默认为1min", required = false) @QueryParam("size") String size,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate);

	@GET
	@Path("/connect")
	@ApiOperation(value = "根据连接数查询性能")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryPerformanceByConnection(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@ApiParam(value = "拓扑节点id", required = true) @QueryParam("nodeId") String nodeId,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate,
			@ApiParam(value = "页码", required = true) @QueryParam("pageIndex") int pageIndex, 
			@ApiParam(value = "每页显示的查询记录数", required = true) @QueryParam("pageSize") int pageSize);
	
	@GET
	@Path("/subtotal")
	@ApiOperation(value = "一段时间内的性能数据小计")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryPerformanceSubTotal(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId,
			@ApiParam(value = "查询类型，service或resource，默认为resource", required = false) @QueryParam("type") String type, 
			@ApiParam(value = "节点id或交易类型", required = true) @QueryParam("targetIds") String targetIds,
			@ApiParam(value = "排序字段", required = false) @QueryParam("orderBy") String orderBy, 
			@ApiParam(value = "排序顺序，true为降序", required = false) @QueryParam("desc")  boolean desc, 
			@ApiParam(value = "每页显示的查询记录数", required = true) @QueryParam("top") int top,
			@ApiParam(value = "页码", required = true) @QueryParam("pageIndex") int pageIndex, 
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate, 
			@ApiParam(value = "用以区分交易模式和非交易模式，其值可为system或business", required = true) @QueryParam("panelId") String panelId);
	
	@GET
	@Path("/transaction/{tradeTypeName}")
	@ApiOperation(value = "查询交易详细信息")
	@Produces(MediaType.APPLICATION_JSON)
	public PerformanceResult queryDetailsPerformanceByTransaction(
			@ApiParam(value = "应用系统id", required = true) @QueryParam("appId") String appId, 
			@ApiParam(value = "交易类型", required = true) @PathParam("tradeTypeName") String tradeTypeName,
			@ApiParam(value = "查询开始时间", required = true) @QueryParam("startDate") long startDate, 
			@ApiParam(value = "查询结束时间", required = true) @QueryParam("endDate") long endDate, 
			@ApiParam(value = "节点id", required = true) @QueryParam("agentId") String agentId);
	
}
